<template>
	<view class="index-container">
		<!-- 顶部提示信息 -->
		<view class="top-btn flex">
			<text class="my-icon home" @tap="toPage('/pages/welcome')"></text>
			<text class="my-icon settings" @tap="toPage('/pages/settings')"></text>
		</view>

		<!-- 活动进度 -->
		<view class="activity-progress">
			<view class="progress-info flex">
				<view class="title">Activity Progress</view>
				<!-- <view class="selector">Weekly<text class="my-icon arrow-down"></text></view> -->
				<view class="selector flex">
					<text class="text">Weekly</text>
					<text class="icon cuIcon-unfold"></text>
				</view>
			</view>
			<view class="progress-bar">
				<view class="current progress-1" :style="`width:${progress}%`" ref="progressBar">
					<image class="bird" src="../static/images/animal/bird.png" mode="aspectFit"></image>
				</view>
			</view>
			<view class="progress-day flex">
				<view v-for="(item, i) in days" :class="getProgressDayClass(i)" :key="i">{{ item }}</view>
			</view>
		</view>

		<!-- 按钮区域 -->
		<view class="btn-area">
			<navigator url="/pages/start/index" class="custom-btn flex start">
				<view class="title">
					<view class="zn">开始我的沙漠历程</view>
					<view class="en">Starting My Desert Journey</view>
				</view>
				<image class="eye" src="../static/images/icon/eye4.png" mode="aspectFit"></image>
				<image class="arrow" src="../static/images/icon/arrow-right.png" mode="aspectFit"></image>
			</navigator>
			<navigator url="/pages/progress/index" class="custom-btn flex statistics">
				<view class="title">
					<view class="zn">眼睛状况记录及统计</view>
					<view class="en">Eye condition recording and statistics</view>
				</view>
				<image class="arrow" src="../static/images/icon/arrow-right.png" mode="aspectFit"></image>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getWeekProgress,
		getSettings
	} from '@/api/system/user'
	import {
		alarmReminder
	} from "@/utils/alarmReminder"
	export default {
		data() {
			return {
				day: -1,
				progress: 0,
				days: ["日", "一", "二", "三", "四", "五", "六"],
				weekProgress: [0]
			}
		},
		onLoad: function() {
			this.day = new Date().getDay();
			getWeekProgress().then((res) => {
				this.getProgressFlags(res);
			});
			alarmReminder();
		},
		onShow: function() {
			setTimeout(() => {
				this.getProgress();
			}, 100);
		},
		methods: {
			toPage(path) {
				this.$tab.navigateTo(path);
			},
			getProgress() {
				const dis = (100 - 6.55) / 6;
				this.progress = 6.55 + this.day * dis;
			},
			getProgressFlags(arr) {
				this.weekProgress = [0];
				arr.forEach(item => {
					const day = new Date(+item.date).getDay();
					this.weekProgress[day] = 1;
				})
				for (let i = 0; i <= this.day; i++) {
					const item = this.weekProgress[i];
					if (item != 1) {
						this.weekProgress[i] = 0;
					}
				}
			},
			getProgressDayClass(index) {
				const value = this.weekProgress[index];
				if (value == 1) {
					return "active";
				} else if (value == 0) {
					return "notDone";
				} else {
					return "";
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	$bdR: 100upx;

	page {
		background-image: url("@/static/images/background/4.main2.jpg");
		background-size: cover;
		padding-top: calc(400upx + 12.65vh);
		height: 100vh;
	}

	.index-container {
		width: 100%;
		padding-bottom: 40upx;

		.top-btn {
			position: absolute;
			top: 90upx;
			right: 40upx;

			.home {
				width: 38upx;
				height: 35upx;
				margin-right: 20upx;
				background-image: url(../static/images/icon/home.png);
			}

			.settings {
				width: 42upx;
				height: 35upx;
				background-image: url(../static/images/icon/settings.png);
			}
		}

		.activity-progress {
			width: 88%;
			margin: 0 auto;
			// margin-top: 55upx;
			margin-top: 3.38vh;

			.progress-info {
				$h: 63upx;
				width: 100%;
				height: $h;
				line-height: $h;
				justify-content: space-between;

				.title {
					font-weight: bold;
				}

				.selector {
					width: 160upx;
					height: $h;
					background-color: #05CA7E;
					border-radius: $bdR;
					color: #fff;

					.text {
						font-size: 18upx;
						padding-left: 35upx;
					}

					.icon {
						font-size: 25upx;
						margin-left: 12upx;
						margin-top: 4upx;
					}
				}
			}

			.progress-bar {
				$h: 42upx;
				width: 100%;
				height: $h;
				// margin-top: 130upx;
				margin-top: 8vh;
				background-color: #fff;
				border-radius: $bdR;

				.current {
					position: relative;
					width: 6.55%;
					height: $h;
					background-color: #02C97D;
					border-radius: $bdR;
					transition: width 1s;

					.bird {
						position: absolute;
						width: 170upx;
						height: 220upx;
						max-width: initial;
						transform: scaleX(-1);
						top: -168upx;
						right: -65upx;
					}
				}
			}

			.progress-day {
				width: 100%;
				margin-top: 20upx;
				justify-content: space-between;

				>view {
					$size: 42upx;
					width: $size;
					height: $size;
					line-height: 40upx;
					text-align: center;
					font-size: 24upx;
					font-weight: bold;
					color: #6D6A6A;
					background-color: initial;
					border-radius: $bdR;
				}

				.active {
					background-color: #000;
					color: #fff;
				}

				.notDone {
					border: 2upx solid #000;
				}
			}
		}

		.btn-area {
			width: 82%;
			margin: 0 auto;
			// margin-top: 132upx;
			margin-top: 8vh;

			.custom-btn {
				height: 195upx;
				background-color: #00D382;
				border-radius: 40upx;
				margin-top: 3.9vh;
				padding: 50upx 3upx 0 40upx;
				color: #fff;
				justify-content: space-between;

				.title {
					margin-right: 40upx;
				}

				.zn {
					font-size: 41upx;
					font-weight: bold;
					letter-spacing: 0.08em;
				}

				.en {
					font-size: 20upx;
					margin-top: 12upx;
					letter-spacing: 0.09em;
				}
			}

			.eye {
				width: 65upx;
				height: 102upx;
			}

			.arrow {
				width: 100upx;
				height: 100upx;
			}
		}
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>